package com.fw.application.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fw.application.controller.base.UserController;
import com.fw.mes.Result;
import com.fw.system.web.model.entity.TbBond;
import com.fw.system.web.model.entity.TbCityCode;
import com.fw.system.web.model.entity.TbCityContent;
import com.fw.system.web.model.entity.TbUser;
import com.fw.system.web.service.ITbBondService;
import com.fw.system.web.service.ITbCityCodeService;
import com.fw.system.web.service.ITbCityContentService;
import com.fw.system.web.service.ITbUserCityJoinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.fw.mes.ResultUtils.success;

/**
 * <p>
 * 解锁城市对应的证券知识内容 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-03-28
 */
@RestController
@RequestMapping("/web/city/content")
@Api(tags = "城市关联的知识，证券知识")
public class TbCityContentController implements UserController {

    @Autowired
    private ITbCityContentService cityContentService;
    @Autowired
    private ITbCityCodeService cityCodeService;
    @Autowired
    private ITbUserCityJoinService cityJoinService;
    @Autowired
    private ITbBondService bondService;


    @GetMapping("/getListByCity")
    @ApiOperation("查询对应城市下的知识 城市id")
    public Result<List<TbCityContent>> getListByCity(@RequestParam String id) {

        TbUser user = this.getUser();
        TbCityCode cityCode = cityCodeService.getById(id);
        if (user.getNowCityCount() < cityCode.getSortCode())
            return new Result().fail(500, "城市还未解锁哦！");
        return success(cityContentService.list(Wrappers.<TbCityContent>lambdaQuery().eq(TbCityContent::getCityCode, id)));
    }

    @GetMapping("/getById")
    @ApiOperation("根据记录id查看详情")
    public Result<TbCityContent> getById(@RequestParam String id){
        TbCityContent byId = cityContentService.getById(id);
        return success(byId);
    }


    @GetMapping("/getList")
    @ApiOperation("查询证券知识讲堂列表")
    public Result getList(@RequestParam(required = false,defaultValue = "1") Integer type) {
        return success(bondService.list(Wrappers.<TbBond>lambdaQuery().eq(TbBond::getBondType, type).orderByAsc(TbBond::getSortCode)));
    }

    @GetMapping("/getDetail")
    @ApiOperation("根据证券知识讲堂记录id查看详情")
    public Result<TbBond> getDetail(@RequestParam String id){
        TbBond byId = bondService.getById(id);
        return success(byId);
    }

}

